Міністерство освіти та науки України
Національний університет “Львівська політехніка”
Інститут комп’ютерних наук та інформаційних технологій
Кафедра автоматизованих систем управління
Лабораторна робота № 3
з дисципліни “Комп’ютерна графіка”
Текст програми:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, Mask, ExtCtrls, Math, Grids;
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
RadioGroup1: TRadioGroup;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
TrackBar1: TTrackBar;
TrackBar2: TTrackBar;
Label1: TLabel;
Label2: TLabel;
procedure OsiXY();
procedure Ploshchuna();
procedure ParalPr();
procedure CosPr();
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
h,w:integer;
dn,dnz,nz,d:integer;
x0,y0,z,x,y:integer;
a:double;
implementation
{$R *.dfm}
procedure TForm1.OsiXY();
var
n:integer;
i:integer;
begin
a:=pi/6;
PaintBox1.Repaint;
h:=PaintBox1.Height;
w:=PaintBox1.Width;
x0:=w div 2;
y0:=h div 2;
with Form1.PaintBox1.Canvas do begin
Pen.Width:=1;
TextOut(w-10,y0+10, 'Z');
TextOut(x0+10,0, 'Y');
TextOut(5,y0+round(tan(a)*x0)+5,'X');
//X
Pen.Color := clBlack;
MoveTo(x0,y0);
LineTo(w,y0);
//Y
Pen.Color := clBlack;
MoveTo(x0,0);
LineTo(x0,y0);
//Z
Pen.Color := clBlack;
MoveTo(x0,y0);
LineTo(0,y0+round(tan(a)*x0));
//Стрілочки Z
MoveTo(0,y0+round(tan(a)*x0));
LineTo(4,y0+round(tan(a)*x0)-10);
MoveTo(0,y0+round(tan(a)*x0));
LineTo(10,y0+round(tan(a)*x0)+1);
//Стрілочки X i Y
MoveTo(w,y0);
LineTo(w-10,y0-5);
MoveTo(w,y0);
LineTo(w-10,y0+5);
MoveTo(x0,0);
LineTo(x0-5,10);
MoveTo(x0,0);
LineTo(x0+5,10);
//Поділки Z
nz:=20;
dnz:=x0;
for i:=1 to x0 do begin
dnz:=dnz-nz;
z:=x0-dnz;
x:=x0-round(z*cos(a));
y:=y0+round(z*sin(a));
MoveTo(x-3,y-3);
LineTo(x+4,y+4);
end;
//Поділки X i Y
dn:=25;
n:=0;
for i := 1 to w do begin
n:=n+dn;
MoveTo(x0+n,y0-5);
LineTo(x0+n,y0+5);
MoveTo(x0-5,y0-n);
LineTo(x0+5,y0-n);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
OsiXY();
Ploshchuna();
if RadioButton1.Checked then ParalPr();
if RadioButton2.Checked then CosPr();
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Close();
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
PaintBox1.Repaint;
end;
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
StringGrid1.ColCount:=5;
StringGrid1.Width:=329;
StringGrid1.Cells[0,1]:='Початкове';
StringGrid1.Cells[1,0]:='X';
StringGrid1.Cells[2,0]:='Y';
StringGrid1.Cells[3,0]:='Z';
StringGrid1.Cells[4,0]:='D';
StringGrid2.Cells[0,1]:='Спроект.';
StringGrid2.Cells[1,0]:='X';
StringGrid2.Cells[2,0]:='Y';
StringGrid2.Cells[3,0]:='Z';
StringGrid2.Cells[1,1]:='';
StringGrid2.Cells[2,1]:='';
StringGrid2.Cells[3,1]:='';
StringGrid1.Cells[1,1]:='0';
StringGrid1.Cells[2,1]:='5';
StringGrid1.Cells[3,1]:='5';
StringGrid1.Cells[4,1]:='3';
end;
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
StringGrid1.ColCount:=4;
StringGrid1.Width:=264;
StringGrid1.Cells[0,1]:='Початкове';
StringGrid1.Cells[1,0]:='L';
StringGrid1.Cells[2,0]:='Alpha';
StringGrid1.Cells[3,0]:='Beta';
StringGrid2.Cells[0,1]:='Спроект.';
StringGrid2.Cells[1,0]:='X';
...